﻿Imports System.Xml

Namespace Spreads
	Public Class GridDataInformation
		Public Property FontStyle As String

		Public Property PointSize As Double?

		Public Property CharacterAki As Double?

		Public Property LineAki As Double?

		Public Property HorizontalScale As Double?

		Public Property VerticalScale As Double?

		Public Property LineAlignment As LineAlignment?

		Public Property GridAlignment As GridAlignment?

		Public Property CharacterAlignment As CharacterAlignment?

		Public Property GridView As GridViewSettings?

		Public Property CharacterCountLocation As CharacterCountLocation?

		Public Property CharacterCountSize As Double?

		Private Property AppliedFont As AppliedFont

		Public Shared Function ReadXml(reader As XmlReader) As GridDataInformation
			Dim gdi As New GridDataInformation()

			If reader.HasAttributes() Then
				gdi.FontStyle = reader.GetAttribute("FontStyle")
				gdi.PointSize = Parser.ParseDouble(reader.GetAttribute("PointSize"))
				gdi.CharacterAki = Parser.ParseDouble(reader.GetAttribute("CharacterAki"))
				gdi.LineAki = Parser.ParseDouble(reader.GetAttribute("LineAki"))
				gdi.HorizontalScale = Parser.ParseDouble(reader.GetAttribute("HorizontalScale"))
				gdi.VerticalScale = Parser.ParseDouble(reader.GetAttribute("VerticalScale"))
				gdi.LineAlignment = Parser.ParseEnum(Of LineAlignment)(reader.GetAttribute("LineAlignment"))
				gdi.GridAlignment = Parser.ParseEnum(Of GridAlignment)(reader.GetAttribute("GridAlignment"))
				gdi.CharacterAlignment = Parser.ParseEnum(Of CharacterAlignment)(reader.GetAttribute("CharacterAlignment"))
				gdi.GridView = Parser.ParseEnum(Of GridViewSettings)(reader.GetAttribute("GridView"))
				gdi.CharacterCountLocation = Parser.ParseEnum(Of CharacterCountLocation)(reader.GetAttribute("CharacterCountLocation"))
				gdi.CharacterCountSize = Parser.ParseDouble(reader.GetAttribute("CharacterCountSize"))
			End If

			While reader.Read()
				Select Case reader.Name
					Case "Properties"
						While reader.Read()
							Select Case reader.Name
								Case "AppliedFont"
									gdi.AppliedFont = AppliedFont.ReadXml(reader)
								Case Else
									If reader.NodeType = XmlNodeType.Element Then
										Debug.WriteLine("Unrecognized element: {0} in element: {1}", reader.Name, "GridDataInformation - Properties")
									End If
							End Select
							If reader.Name = "Properties" And reader.NodeType = XmlNodeType.EndElement Then Exit While
						End While
					Case "GridDataInformation"
						If reader.NodeType = XmlNodeType.EndElement Then
							Exit While
						End If
					Case Else
						If reader.NodeType = XmlNodeType.Element Then
							Debug.WriteLine("Unrecognized element: {0} in element: {1}", reader.Name, "GridDataInformation")
						End If
				End Select
			End While


			Return gdi
		End Function
	End Class
End Namespace